package com.cuixichang.minimalism.acl;

import cn.hutool.core.util.StrUtil;
import com.cuixichang.minimalism.basal.base.Validate;
import com.cuixichang.minimalism.basal.enums.IsEnableEnum;
import com.cuixichang.minimalism.basal.enums.SubassemblyTypeEnum;
import com.cuixichang.minimalism.basal.utils.RegexValidateUtil;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class DateTimeSubassemblyDesign extends SubassemblyDesignAbs{
    @Override
    public SubassemblyTypeEnum getType() {
        return SubassemblyTypeEnum.DateTime;
    }

    @Override
    public Validate structureValidate(String structure) {
        return Validate.builder().checked(true).message(IsEnableEnum.YES.getDesc()).build();
    }

    @Override
    public Validate valueValidate(String structure, String value) {
        boolean pass = RegexValidateUtil.checkDateTime(value);
        return Validate.builder().checked(pass).message(pass ? IsEnableEnum.YES.getDesc():"日期值格式检验不通过").build();
    }

        @Override
    public String previewValue(String structure, Object value) {
        return Objects.nonNull(value)?String.valueOf(value): StrUtil.EMPTY;
    }

    @Override
    public Object resultValue(String value) {
        return value;
    }

    @Override
    public String resultValue(Object value) {
        return String.valueOf(value);
    }
}
